#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>

using namespace std;

const int N = 1e5 + 10;

int arr[N];
int q[N];
int main()
{
	int n, k;
	cin >> n;
	for(int i = 0; i < n; i ++)
	{
		cin >> k;
		q[i] = k;
		while(k != 1)
		{
			if(k % 2 != 0) k = 3 * k + 1;
			k /= 2;
			if(arr[k] == 1) break;
			arr[k] = 1;
		}
	}

	bool flag = 0;
	sort(q, q + n);

	for(int i = n - 1; i >= 0; i --)
	{
		if(arr[q[i]] == 0) 
		{
			if(flag == true) cout << " ";
			cout << q[i];
			flag = true;
		}
	}
	return 0;
}